<?php
include($folder.'/layouts/code-behind/backend.php');
if ($_POST['filters']['megnevezes_previous'] !== $_POST['filters']['megnevezes'])
{
//	$_POST['main']['sortColumn'] = null;
//	$_POST['main']['sortDirection'] = null;
//	$_POST['main']['itemsPerPage'] = null;
	$_POST['main']['block'] = null;
}
function blc_unnepek_select($from, $itemsPerPage, $sortColumn, $sortDirection, $megnevezes)
{
	$orderBy = $sortColumn.'_'.$sortDirection;
	if (!ReplaceStringNullOrEmpty($megnevezes, null))
		$megnevezes = str_replace('*', '%', $megnevezes);
	return query('
		SELECT 
			f.id AS id, 
			m.name AS month_name, 
			f.dayofmonth AS dayofmonth, 
			f.name AS name, 
			f.month_id AS month_id
		FROM feast f
			INNER JOIN month m 
				ON m.id = f.month_id
		WHERE :megnevezes IS NULL OR f.name LIKE :megnevezes
		ORDER BY
			CASE WHEN :orderBy = \'month_id_asc\' THEN f.month_id END ASC,
			CASE WHEN :orderBy = \'month_id_asc\' THEN f.dayofmonth END ASC,
			CASE WHEN :orderBy = \'month_id_desc\' THEN f.month_id END DESC,
			CASE WHEN :orderBy = \'month_id_desc\' THEN f.dayofmonth END DESC,
			CASE WHEN :orderBy = \'name_asc\' THEN f.name END ASC,
			CASE WHEN :orderBy = \'name_desc\' THEN f.name END DESC
		LIMIT :from,:itemsPerPage', 
		array('from'=>$from, 'itemsPerPage'=>$itemsPerPage, 'orderBy'=>$orderBy, 'megnevezes'=>$megnevezes));
}
function blc_unnepek_select_count($megnevezes)
{
	if (!ReplaceStringNullOrEmpty($megnevezes, null))
		$megnevezes = str_replace('*', '%', $megnevezes);
	return queryScalar('SELECT COUNT(*) FROM feast WHERE :megnevezes IS NULL OR name LIKE :megnevezes',
		array('megnevezes' => $megnevezes));
}
?>